package com.sanda.androidcourse.strategy.bind;

import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.ViewModelProvider;
import androidx.databinding.DataBindingUtil;

import com.sanda.androidcourse.R;
import com.sanda.androidcourse.databinding.ActivityCalculatorMvvmactivityBinding;

public class BindActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // 使用 DataBinding 设置布局并绑定 ViewModel
        ActivityCalculatorMvvmactivityBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_calculator_mvvmactivity);

        // 获取 ViewModel 实例
        CalculateViewModel vm = new ViewModelProvider(this).get(CalculateViewModel.class);

        // 绑定 ViewModel 和布局
        binding.setVm(vm);

        // 设置生命周期所有者，确保 LiveData 能够自动观察和更新
        binding.setLifecycleOwner(this);
    }
}
